package com.video.controller;

import com.video.result.ResultVO;
import com.video.config.MinIOConfig;
import com.video.utils.MinIOUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * @author baoshuai
 * @date 2022/12/15
 */
@Api(tags = "文件接口模块")
@RestController
public class FileUploadController {

    @Resource
    private MinIOConfig minIOConfig;

    @ApiOperation("上传视频")
    @PostMapping("upload")
    public ResultVO upload(MultipartFile file) throws Exception {
        String fileName = file.getOriginalFilename();

//        MinIOUtils.uploadFile(minIOConfig.getBucketName(),
//                fileName,
//                file.getInputStream());
        MinIOUtils.uploadFile(minIOConfig.getBucketName(),
                file,
                fileName,
                "video/mp4");

        String imgUrl = minIOConfig.getFileHost()
                + "/"
                + minIOConfig.getBucketName()
                + "/"
                + fileName;

        return ResultVO.success(imgUrl);
    }

    @ApiOperation("测试文件上传")
    @PostMapping
    public ResultVO testUpload(MultipartFile file) {
        return ResultVO.success();
    }
}
